#include <iostream>
#include <string.h>
using namespace std;

//128个字符
#define MAX_LEN 128


class TrieNode
{
    public:
        int count = 0; //以该节点结尾的 字符串 个数
        TrieNode * childs[MAX_LEN] = {NULL};  
};

class TrieTree
{
    public:
    TrieNode root;
    void insert(char * str);
    bool search(char * str);
    bool delete_string(char * str);
};

void TrieTree::insert(char * str)
{
    TrieNode * currNode = &root;
    int str_len = strlen(str);
    for(int i=0;i<str_len;i++)
    {
        if(currNode->childs[str[i]]==NULL)
        {
            currNode->childs[str[i]] = new TrieNode;
        }
        currNode = currNode->childs[str[i]]; 
    }
    currNode ->count ++;
}

bool TrieTree::search(char * str)
{
    TrieNode * currNode = &root;
    int str_len = strlen(str);

    for(int i=0;i<str_len;i++)
    {
        if(currNode == NULL || currNode->childs[str[i]]==NULL)
        {
           return false;
        }
        currNode = currNode->childs[str[i]]; 
    }
    return currNode->count != 0;
}
bool TrieTree::delete_string(char * str)
{
    TrieNode * currNode = &root;
    int str_len = strlen(str);

    for(int i=0;i<str_len;i++)
    {
        if(currNode == NULL || currNode->childs[str[i]]==NULL)
        {
           return true;
        }
        currNode = currNode->childs[str[i]]; 
    }
    if(currNode->count >0)
    {
        currNode->count --;
    }
    return true;
}

int main()
{
    TrieTree tree;
    tree.insert("n");
    tree.insert("nieelo");
    tree.delete_string("n");
    cout<<tree.search("n")<<endl;
    cout<<tree.search("nieelo")<<endl;
    return 0;
}